package com.wms.controller;

import com.wms.bean.ResultBean;
import com.wms.core.R;
import com.wms.entity.Category;
import com.wms.service.CategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Api(tags = "类别管理")
@Slf4j
@RequestMapping("/api")
public class CategoryController {
    @Autowired
    CategoryService categoryService;

    @GetMapping("/category")
    @ApiOperation(value = "查询物料类别")
    public ResultBean getCategory(){
        log.info("正在查询物料类别...");
        List<Category> list=categoryService.getCategory();
        return R.success("详情",list);
    }

    @PostMapping("/category")
    @ApiOperation("新增类别")
    public ResultBean saveCategory(@RequestBody Category category){
        int rs=categoryService.saveCategory(category);
        return rs==1?R.success("新增成功"):R.fail("新增失败");
    }
}
